package com.pyip.order.service;


import com.pyip.feign.client.UserClient;
import com.pyip.feign.pojo.User;
import com.pyip.order.mapper.OrderMapper;
import com.pyip.order.pojo.Order;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class OrderService {

    @Autowired
    private OrderMapper orderMapper;

//    @Autowired
//    private RestTemplate restTemplate;
//    /**
//     * 返回order信息（内部封闭user)
//     * @param orderId
//     * @return
//     */
//    public Order queryOrderById(Long orderId){
//        // 1.查询订单
//        Order order = orderMapper.findById(orderId);
//        // 2 查询user表信息
////        String url = "http://localhost:8081/user/"+order.getUserId();
////        使用eureka服务发现
//        String url = "http://userservice/user/"+order.getUserId();
//        // 发起调用
//        User user = restTemplate.getForObject(url, User.class);
//        // 3 存入order中
//        order.setUser(user);
//        // 4.返回
//        return order;
//    }

    @Autowired
    private UserClient userClient;

    public Order queryOrderById(Long orderId){
        // 1.查询订单
        Order order = orderMapper.findById(orderId);
        // 2 查询user表信息
//        String url = "http://localhost:8081/user/"+order.getUserId();
//        使用eureka服务发现
        User user = userClient.findById(order.getUserId());
            // 3 存入order中
        order.setUser(user);
        // 4.返回
        return order;
    }

}
